/***********************************************************************
 * Module:  Etudiant.java
 * Author:  Alexandro
 * Purpose: Defines the Class Etudiant
 ***********************************************************************/

package dao;

import java.util.*;
import java.sql.*;

public class Etudiant implements InterfaceDAO {
   private int matricule;
   private String nom;
   private String prenom;
   private String adresse;
   private String tel;
   
   private Module[] module;
   
   public EpreuveRendu[] notes;
   
   public int getMatricule() {
      return matricule;
   }
   
   /** @param newMatricule */
   public void setMatricule(int newMatricule) {
      matricule = newMatricule;
   }
   
   public String getNom() {
      return nom;
   }
   
   /** @param newNom */
   public void setNom(String newNom) {
      nom = newNom;
   }
   
   public String getPrenom() {
      return prenom;
   }
   
   /** @param newPrenom */
   public void setPrenom(String newPrenom) {
      prenom = newPrenom;
   }
   
   public String getAdresse() {
      return adresse;
   }
   
   /** @param newAdresse */
   public void setAdresse(String newAdresse) {
      adresse = newAdresse;
   }
   
   public String getTel() {
      return tel;
   }
   
   /** @param newTel */
   public void setTel(String newTel) {
      tel = newTel;
   }
   
   public int insert(int[] params) {
      
       try {			
			dao.DAODataConnection.executer("INSERT INTO etudiant(matricule,nom,prenom,adresse,tel)"+
										   "VALUES("+getMatricule()+",'"+getNom()+"','"+getPrenom()+"','"+getAdresse()+"','"+getTel()+ "');");											
			return 0;			
			}		
		catch(Exception e){ System.out.println(e); }		
		
		return 1;
		
   }
   
   public Object[] select(int[] param) {
      
       try {			
			
			ResultSet table = dao.DAODataConnection.executerQuery("SELECT * FROM etudiant");											
			Vector sortie = new Vector();			
			while(table.next() )	
			{
				Etudiant neuf = new Etudiant();
				neuf.setMatricule(table.getInt(1));
				neuf.setNom(table.getString(2));
				neuf.setPrenom(table.getString(3));
				neuf.setAdresse(table.getString(4));
				neuf.setTel(table.getString(5));				
				
				sortie.add(neuf);				
			}		
			return sortie.toArray();			
			}
			
		catch(Exception e){ System.out.println(e); }		
		
		return null;
		
   }
   
   public int delete(int[] param) {
      
       try {			
			dao.DAODataConnection.executer("DELETE FROM etudiant WHERE matricule="+getMatricule());											
			return 0;			
			}		
		catch(Exception e){ System.out.println(e); }		
		
		return 1;
		
   }
   
   public int update(int[] params) {
      
       try {			
			dao.DAODataConnection.executer("UPDATE etudiant SET "+
										   "nom='"+getNom()+"',"+
										   "prenom='"+getPrenom()+"',"+
										   "adresse='"+getAdresse()+"',"+
										   "tel='"+getTel()+ "' where matricule="+getMatricule());											
			return 0;			
			}		
		catch(Exception e){ System.out.println(e); }		
		
		return 1;
		
		
   }
   public int inscrire(int[] params){
   	try {			
			dao.DAODataConnection.executer("INSERT INTO ETU_EST_INSCRIT (matricule,code_dip,no_annee) "+
										   "VALUES("+getMatricule()+","+params[0]+","+params[1]+")");											
			return 0;			
			}		
		catch(Exception e){ System.out.println(e); }		
		
		return 1;
		
   	
   }

	public int affecterModule(int[] params){
   	
   	try {			
			dao.DAODataConnection.executer("INSERT INTO ETU_SUIT_MOD (matricule,code_mod) "+
										   "VALUES("+getMatricule()+","+params[0]+")");											
			return 0;			
			}		
		catch(Exception e){ System.out.println(e); }		
		
		return 1;
		
		
   }
   
   public int passerEpreuve(int[] params, float note, boolean estPresent){
   	
   	try {			
			dao.DAODataConnection.executer("INSERT INTO ETU_PASSE_EPR (matricule,session,code_epr, note, present)"+
										   " VALUES("+getMatricule()+","+params[0]+","+params[1]+","+note+","+estPresent+")");											
			return 0;			
			}		
		catch(Exception e){ System.out.println(e); }		
		
		return 1;
		
   }
}